import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
// 配置 Element Plus 按需导入
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 把你需要的组件的 css 或者 sass 文件自动引入进来
import ElementPlus from 'unplugin-element-plus/vite'
// 提供 Vue 3 单文件组件支持
import vue from '@vitejs/plugin-vue'
import autoprefixer from 'autoprefixer'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString()
          }
        },
      },
    },
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      resolvers: [ElementPlusResolver()],
      dts:'src/types/auto-import.d.ts',
    }),
    Components({
      resolvers:[ElementPlusResolver()],
      dts:"src/types/components.d.ts"
    }),
    ElementPlus({})
  ],
  server:{
    host:'127.0.0.1',
    port:3000,
    cors:true,
    proxy:{
      '/api':{
        target:'https://dev-community-web-40017-8-1317259555.sh.run.tcloudbase.com',
        changeOrigin:true
      }
    }
  },
  resolve:{
    alias:{
      // 设置'@' 指向 'src 目录(
      '@':path.join(__dirname,'./src')
    }
  },
  css:{
    postcss:{
      plugins:[autoprefixer()],
    }
  }
  
})
